import { Expose, Type } from "class-transformer";
import { BaseEntity } from "src/database/base/base.entity";
import { Column, CreateDateColumn, DeleteDateColumn, Entity, OneToMany } from "typeorm";
import { AccessTokenEntity } from "./access-token.entity";

@Entity('users')
export class UserEntity extends BaseEntity {
    @Expose()
    @Column({
        comment: '姓名',
        nullable: true,
    })
    nickname?: string;

    @Expose()
    @Column({ comment: '用户名', unique: true })
    username!: string;

    @Column({ comment: '密码', length: 500, select: false })
    password!: string;

   
    @Column({ comment: '手机号', nullable: true, unique: true })
    phone?: string;

    
    @Column({ comment: '邮箱', nullable: true, unique: true })
    email?: string;

   
    @Type(() => Date)
    @CreateDateColumn({
        comment: '用户创建时间',
    })
    createdAt!: Date;

    @Expose()
    @Type(() => Date)
    @DeleteDateColumn({
        comment: '用户更新时间',
    })
    updatedAt!: Date;

    @OneToMany(() => AccessTokenEntity, (accessToken) => accessToken.user, {
        cascade: true,
    })
    accessTokens:string


    @Type(() => Date)
    @DeleteDateColumn({
        comment: '删除时间',
    })
    deletedAt!: Date;
}
